package com.netease.nie.facade;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.netease.nie.base.cdn.CDNProperties;
import com.netease.nie.base.utils.CopyUtils;
import com.netease.nie.dto.DrawLotterySettingDto;
import com.netease.nie.model.DrawLotterySetting;
import com.netease.nie.service.DrawLotterySettingService;

/**
 * 抽奖入口配置业务接口实现
 * @author gzlibingjie
 */
@Service
public class DrawLotterySettingFacadeImpl implements DrawLotterySettingFacade {
	
	@Autowired
	private DrawLotterySettingService drawLotterySettingService;
	
	@Autowired
	private CDNProperties cdnProperties;
	
	/**
	 * 获取抽奖活动入口配置
	 * @return 抽奖活动入口配置
	 */
	@Override
	public DrawLotterySettingDto query() {
		DrawLotterySettingDto drawLotterySettingDto = new DrawLotterySettingDto();
		DrawLotterySetting drawLotterySetting = drawLotterySettingService.query();
		if (drawLotterySetting != null) {
			CopyUtils.copy(drawLotterySettingDto, drawLotterySetting);
			
			// 设置封面图
			String coverWapUrl = drawLotterySetting.getCoverWapUrl();
			if (StringUtils.isNotBlank(coverWapUrl)) {
				drawLotterySettingDto.setCoverUrl(cdnProperties.getCdnPrefix() + coverWapUrl);
			}
			
			// 设置封面备用图
			String coverBackupWapUrl = drawLotterySetting.getCoverBackupWapUrl();
			if (StringUtils.isNotBlank(coverBackupWapUrl)) {
				drawLotterySettingDto.setCoverBackupUrl(cdnProperties.getCdnPrefix() + coverBackupWapUrl);
			}
		}
		return drawLotterySettingDto;
	}

}
